package kz.pompei.var.model;

import java.util.HashMap;
import java.util.Map;

import kz.pompei.var.error.ErrorReciever;

public class Pack {
  private final boolean root;
  private final Pack parent;
  private final String name;
  private final ErrorReciever errorReciever;
  private final Map<String, Pack> children = new HashMap<String, Pack>();
  
  Pack(ErrorReciever errorReciever) {
    this.errorReciever = errorReciever;
    root = true;
    name = null;
    parent = this;
  }
  
  private Pack(String name, Pack parent) {
    this.name = name;
    this.parent = parent;
    errorReciever = parent.errorReciever;
    root = false;
  }
  
  Pack getChild(String childName) {
    {
      Pack ret = children.get(childName);
      if (ret != null) return ret;
    }
    {
      Pack ret = new Pack(childName, this);
      children.put(ret.getName(), ret);
      return ret;
    }
  }
  
  public boolean isRoot() {
    return root;
  }
  
  public String getName() {
    return name;
  }
  
  public Pack getParent() {
    return parent;
  }
  
}
